home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / irit / rend386 / polyblit / fpblitn.asm < prev    next >
Encoding:
Assembly Source File  |  1992-12-06  |  4.5 KB  |  230 lines

  1.     TITLE    FPBLIT - Fast poly filling blitter
  2.     NAME    FPBLIT
  3.  
  4.  
  5.     COMMENT    $
  6.  
  7.     Name:        FPBLIT
  8.  
  9.         Written and (c) by Dave Stampe 9/11/91
  10.         Not for commercial use, so get permission
  11.         before marketing code using this stuff!
  12.         For private PD use only.
  13.  
  14.         $
  15.  
  16.     COMMENT    $
  17.  
  18.     Name:        tpoly
  19.  
  20.     Caller:        C:
  21.  
  22.             int tpoly(int x1, int x2, long l_incr, long r_incr,
  23.                   int y1, int y3);
  24.  
  25.             x1 = left side start, x2 = right side start
  26.              if 0x8000, uses end of last poly's side for cont.
  27.             y1 = top, y2 = 1+bottom of poly slice
  28.             l_incr, r_incr = 2^16 times slope (add to x each line)
  29.  
  30.         $
  31.  
  32.  
  33.         .MODEL large
  34.  
  35.         .CODE
  36.                 ; big table more eff. than masking
  37.                 ; start byte lookup table
  38. stmask:        REPT    40
  39.         db    0ffh,07fh,03fh,01fh,00fh,007h,003h,001h
  40.         ENDM
  41.                 ; end byte lookup table
  42. fnmask:         REPT    40
  43.         db      080h,0c0h,0e0h,0f0h,0f8h,0fch,0feh,0ffh
  44.         ENDM
  45.  
  46.  
  47. x1    equ    [bp+6]          ; arguments to _tpoly
  48. x2    equ    [bp+8]
  49. l_incr    equ    [bp+10]
  50. r_incr    equ    [bp+14]
  51. y1    equ    [bp+18]
  52. y3    equ    [bp+20]
  53.  
  54. vline   equ    [bp-2]       ; video base addr. of line
  55. lines    equ    [bp-4]        ; number of lines to fill
  56.  
  57.     extrn    _l_hold         ; holds full res. L, R. point
  58.     extrn    _r_hold
  59.  
  60.     extrn    _dpaddr        ; page base address
  61.  
  62.    ;
  63.    ;    tpoly(int x1,int x2, long l_incr, long r_incr, int y1, int y3)
  64.    ;
  65.  
  66.         PUBLIC    _tpoly
  67.  
  68. _tpoly    proc    far
  69.  
  70.     .386
  71.     push    bp
  72.     mov    bp,sp
  73.     sub    sp,6
  74.     push    si
  75.     push    di
  76.  
  77.     mov    ax,word ptr y3           ; if(y3-y1<1)return(-1);
  78.     sub    ax,word ptr y1
  79.     cmp    ax,1
  80.     jge    short continue
  81. clipall:
  82.     mov    ax,65535               ; return -1 on bad args
  83.     jmp    exit
  84.  
  85. continue:
  86.     cld
  87.     mov    ax,0a000h              ; set video segment
  88.     mov    es,ax
  89.  
  90.     mov    edx,DWORD PTR ds:_l_hold
  91.     mov    ax,x1
  92.     cmp    ax,8000h               ; old or new left side
  93.     je    short nlload
  94.     mov    dx,ax
  95.     shl    edx,16
  96.     add    edx,08000h             ; force left side to round up
  97. nlload:
  98.     mov    esi,DWORD PTR ds:_r_hold
  99.     mov    ax,x2
  100.     cmp    ax,8000h               ; old or new right
  101.     je    short nrload
  102.     mov    si,ax
  103.     shl    esi,16
  104. nrload:
  105.     mov    ax,y3                   ; compute # lines
  106.     sub    ax,y1
  107.     mov    lines,ax
  108.     mov    al,y1
  109.     mov    bl,40                   ; compute starting line adr
  110.     mul    bl
  111.     add    ax,WORD PTR ds:_dpaddr
  112.     mov    vline,ax
  113.  
  114.     mov    ebx,edx                 ; convert fixed-pt to integer
  115.     sar    ebx,16
  116.     mov    ecx,esi
  117.     sar    ecx,16
  118.     jl    short doneline          ; preclip left trap
  119.  
  120.     cmp    bx,0
  121.     jl    short clipall
  122.     cmp    cx,640
  123.     ja    short clipall
  124.  
  125.  
  126. nextline:
  127.         ; start of fast h line blitter:
  128.         ;  bx=left side, cx=right side, vline=line start
  129.  
  130.     mov    al,BYTE PTR cs:[bx+stmask]  ; left mask
  131.     shr    bx,3                        ; left address
  132.  
  133.     mov    di,cx
  134.     mov    ah,BYTE PTR cs:[di+fnmask]  ; right mask
  135.     shr    cx,3                        ; right address
  136.  
  137.     mov    di,vline            ; start address
  138.     add    di,bx
  139.     sub    cx,bx                       ; number of bytes-1
  140.     je    short onebyte
  141.     jc    short doneline              ; clip trap
  142.  
  143.     and    es:[di],al                  ; mask first byte
  144.     inc    di
  145.     dec    cx                          ; mask rest
  146.     mov    al,0ffh                     ; rep faster than test and jmp
  147.     rep    stosb                       ; for zero byte case
  148.     and    es:[di],ah                  ; mask last byte
  149.     jmp    short doneline
  150.  
  151. onebyte:
  152.     and    al,ah
  153.     and    es:[di],al        ; single byte mask
  154.  
  155. doneline:
  156.     mov    ax,40                   ; next line address
  157.     add    vline,ax
  158.  
  159.     add    edx,DWORD PTR l_incr    ; step left, right edges
  160.     add    esi,DWORD PTR r_incr
  161.     mov    ebx,edx            ; convert fixed pt to integer
  162.     sar    ebx,16
  163.     mov    ecx,esi
  164.     sar    ecx,16
  165.  
  166.     dec    WORD PTR lines          ; done lines?
  167.     jg    short nextline
  168.  
  169.    ;    sub    edx,DWORD PTR l_incr    ; DON'T unstep left, right edges
  170.    ;    sub    esi,DWORD PTR r_incr    ; as this helps fill in gaps
  171.  
  172. donetri:                                   ; finished all drawing
  173.     mov    DWORD PTR ds:_l_hold,edx   ; store edge points in case
  174.     mov    DWORD PTR ds:_r_hold,esi   ; needed for next poly slice
  175. exit:
  176.     pop    di                         ; exit code
  177.     pop    si
  178.     mov    sp,bp
  179.     pop    bp
  180.     ret
  181.  
  182. _tpoly    endp
  183.  
  184.  
  185.    ;
  186.    ;    long compute_slope(int x1, int y1, int x2, int y2)
  187.    ;
  188.  
  189. y1    equ    [bp+8]
  190. y2    equ    [bp+12]
  191. x1    equ    [bp+6]
  192. x2    equ    [bp+10]
  193.  
  194.     PUBLIC    _compute_slope
  195.  
  196. _compute_slope    proc    far
  197.  
  198.     push    bp        ; computes slope (dy incrementor)
  199.     mov    bp,sp           ; with 16-bit underflow
  200.     sub    sp,4
  201.     .386
  202.     xor    ecx,ecx
  203.     mov    cx,y2
  204.     sub    cx,y1
  205.     je    short @5@386    ; skip if zero divide (special case)
  206.     mov    ax,x2           ; detected later by y1==y2 test
  207.     sub    ax,x1
  208.     cwd
  209.     movsx    eax,ax      ; (x2-x1)/(y2-y1)
  210.     movsx    edx,dx
  211.     shl    eax,16
  212.     idiv    ecx
  213.     cmp        eax,0       ; round up if pos (neg already rounded up)
  214.     jle    short @5@386
  215.     inc    eax
  216. @5@386:                         ; return long value (286 style)
  217.     mov    [bp-4],eax
  218.     mov    dx,word ptr [bp-2]
  219.     mov    ax,word ptr [bp-4]
  220.     mov    sp,bp
  221.     pop    bp
  222.     ret
  223.  
  224. _compute_slope    endp
  225.  
  226.  
  227.     end
  228.  
  229.  
  230.